package com.example.lenovo.demo.presenter;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

import com.example.lenovo.demo.model.Model;
import com.example.lenovo.demo.model.databean.CityFirstHotBean;
import com.example.lenovo.demo.model.databean.CityFirstHotTabmsgBean;
import com.example.lenovo.demo.model.idatabean.IModel;
import com.example.lenovo.demo.model.idatabean.OnCityFirstHotSuccess;
import com.example.lenovo.demo.model.idatabean.OnCityFirstHotTabMsgSuccess;
import com.example.lenovo.demo.presenter.adapter.CityFirstHotVpAdater;
import com.example.lenovo.demo.view.CityFirstHotFragment;
import com.example.lenovo.demo.view.FgManager;
import com.example.lenovo.demo.view.ifgview.ICityFirstHotActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2017/1/15.
 */

public class CityFirstHotAcPresenter implements ICityFirstHotActivity{
    private ViewPager viewPager;
    private Context context;
    private Toolbar toolbar;
    private TabLayout tabLayout;
    private TextView textView;
    private int num;
    private String id;
    private IModel iModel;
    private String city;
    public static ProgressDialog progressDialog;
    private String[] arrId;
    private String[] arrMsg;
    private List<CityFirstHotFragment> fragments;
    private CityFirstHotVpAdater adater;
    private FragmentManager manager;


    public void initData(){
        progressDialog.show();
        initToolBar();
        fragments=new ArrayList<>();
        iModel=new Model();
        iModel.sendCityFirstHotMsg(id, new OnCityFirstHotTabMsgSuccess() {
            @Override
            public void OnCityFirstHotTabMsgSuccess(CityFirstHotTabmsgBean cityFirstHotTabmsgBean) {
                arrMsg=new String[cityFirstHotTabmsgBean.getData().size()];
                arrId=new String[cityFirstHotTabmsgBean.getData().size()];
                for (int i = 0; i < cityFirstHotTabmsgBean.getData().size(); i++) {
                    arrMsg[i]=cityFirstHotTabmsgBean.getData().get(i).getAlias_name();
                    arrId[i]=cityFirstHotTabmsgBean.getData().get(i).getId()+"";
                }
                for (int i = 0; i < arrId.length; i++) {
                    fragments.add(CityFirstHotFragment.getFragment(arrId[i]));
                }
                adater=new CityFirstHotVpAdater(manager,fragments,arrMsg);
                viewPager.setAdapter(adater);
                viewPager.setOffscreenPageLimit(3);
                tabLayout.setupWithViewPager(viewPager);
                viewPager.setCurrentItem(num);
            }

            @Override
            public void OnCityFirstHotTabMsgFaild() {

            }
        });
        textView.setText(city+"旅行榜单");

    }

    private void initToolBar() {
        tabLayout.setTabTextColors(Color.parseColor("#FFFFFF"),Color.parseColor("#FFFFFF"));
        tabLayout.setSelectedTabIndicatorHeight(4);
        tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFFFFF"));

    }

    @Override
    public void sendView(ViewPager viewPager, Context context, Toolbar toolbar, TabLayout tabLayout, TextView textView, String id, ProgressDialog progressDialog, FragmentManager manager,int num,String city) {
        this.context=context;
        this.id=id;
        this.textView=textView;
        this.viewPager=viewPager;
        this.tabLayout=tabLayout;
        this.toolbar=toolbar;
        this.progressDialog=progressDialog;
        this.manager=manager;
        this.num=num;
        this.city=city;
    }

}
